/* Copyright 2009
 *
 * This program and the accompanying materials
 * are made available under the terms of the
 * Eclipse Public License v1.0 which accompanies
 * this distribution, and is available at
 *
 * 		http://www.eclipse.org/legal/epl-v10.html
 *
 * Unless required by applicable law or agreed to in
 * writing, software distributed under the License is
 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
 * OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing
 * permissions and limitations under the License.
 *
 * Contributors:
 * 	   IBM Corporation - initial API and implementation for JDT/DLTK
 *     Sean W. Quinn - initial adoption for use with PHP from various sources.
 */
package org.eclipse.php.internal.ui.preferences.formatter.profile;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import org.eclipse.core.runtime.preferences.IScopeContext;
import org.eclipse.dltk.ui.formatter.IProfile;
import org.eclipse.dltk.ui.formatter.ProfileKind;
import org.eclipse.php.core.formatter.PHPCodeFormatterConstants;
import org.eclipse.php.internal.core.PHPCoreConstantsExt;
import org.eclipse.php.internal.ui.preferences.PreferenceConstants;
import org.eclipse.php.internal.ui.preferences.PreferencesAccess;
import org.eclipse.php.internal.ui.preferences.formatter.KeySet;
import org.eclipse.php.internal.ui.preferences.formatter.PHPFormatterMessages;
import org.eclipse.php.ui.PHPUiHelper;

/**
 *
 * @author Sean W. Quinn (swquinn@gmail.com)
 */
@SuppressWarnings("restriction")
public class PHPFormatterProfileManager extends PHPProfileManager {

	public final static String ECLIPSE_DEFAULT_PROFILE = "org.eclipse.php.ui.default.default_profile"; //$NON-NLS-1$
	public final static String ECLIPSE_PROFILE = "org.eclipse.php.ui.default.eclipse_profile"; //$NON-NLS-1$
	public final static String PHP_PROFILE = "org.eclipse.php.ui.default.pdt_profile"; //$NON-NLS-1$

	public final static String DEFAULT_PROFILE = ECLIPSE_PROFILE;

	private final static KeySet[] KEY_SETS = new KeySet[] {
			new KeySet(PHPCoreConstantsExt.PLUGIN_ID, new ArrayList(PHPCodeFormatterConstants
					.getPHPConventionsSettings().keySet())), new KeySet(PHPUiHelper.UI_PLUGIN_ID, Collections.EMPTY_LIST) };

	private final static String PROFILE_KEY = PreferenceConstants.FORMATTER_PROFILE;
	private final static String FORMATTER_SETTINGS_VERSION = "formatter_settings_version"; //$NON-NLS-1$

	public PHPFormatterProfileManager(final List<PHPProfile> profiles, final IScopeContext context,
			final PreferencesAccess preferencesAccess, final PHPProfileVersioner profileVersioner) {
		super(addBuiltinProfiles(profiles, profileVersioner), context, preferencesAccess, profileVersioner, KEY_SETS,
				PROFILE_KEY, FORMATTER_SETTINGS_VERSION);
	}

	private static List<PHPProfile> addBuiltinProfiles(List<PHPProfile> profiles, PHPProfileVersioner profileVersioner) {
		final PHPProfile phpProfile = new BuiltInProfile(PHP_PROFILE,
				PHPFormatterMessages.ProfileManager_php_conventions_profile_name, getPHPSettings(), 1, profileVersioner
						.getCurrentVersion(), profileVersioner.getProfileKind());
		profiles.add(phpProfile);

		final PHPProfile eclipseProfile = new BuiltInProfile(ECLIPSE_PROFILE,
				PHPFormatterMessages.ProfileManager_eclipse_profile_name, getEclipseSettings(), 2, profileVersioner
						.getCurrentVersion(), profileVersioner.getProfileKind());
		profiles.add(eclipseProfile);

		final PHPProfile defaultProfile = new BuiltInProfile(ECLIPSE_DEFAULT_PROFILE,
				PHPFormatterMessages.ProfileManager_default_profile_name, getDefaultSettings(), 3, profileVersioner
						.getCurrentVersion(), profileVersioner.getProfileKind());
		profiles.add(defaultProfile);
		return profiles;
	}

	/**
	 * @return Returns the default settings.
	 */
	public static Map<String, String> getDefaultSettings() {
		return getEclipseSettings();
	}

	/**
	 * @return Returns the settings for the new eclipse profile.
	 */
	public static Map<String, String> getEclipseSettings() {
		final Map<String, String> options = PHPCodeFormatterConstants.getEclipseDefaultSettings();
		//PHPProfileVersioner.setLatestCompliance(options);
		return options;
	}

	/**
	 * @return Returns the settings for the Java Conventions profile.
	 */
	public static Map<String, String> getPHPSettings() {
		final Map<String, String> options = PHPCodeFormatterConstants.getPHPConventionsSettings();
		//PHPProfileVersioner.setLatestCompliance(options);
		return options;
	}

	@Override
	public PHPProfile getDefaultProfile() {
		return getProfile(DEFAULT_PROFILE);
	}

  public void addProfile(IProfile arg0) {
    // TODO Auto-generated method stub

  }

  public void clearDirty() {
    // TODO Auto-generated method stub

  }

  public IProfile create(ProfileKind arg0, String arg1,
      Map<String, String> arg2, String arg3, int arg4) {
    // TODO Auto-generated method stub
    return null;
  }

  public boolean deleteProfile(IProfile arg0) {
    // TODO Auto-generated method stub
    return false;
  }

  public IProfile findProfile(String arg0) {
    // TODO Auto-generated method stub
    return null;
  }

  public boolean isDirty() {
    // TODO Auto-generated method stub
    return false;
  }

  public void markDirty() {
    // TODO Auto-generated method stub

  }

  public IProfile rename(IProfile arg0, String arg1) {
    // TODO Auto-generated method stub
    return null;
  }

  public void setSelected(IProfile arg0) {
    // TODO Auto-generated method stub
  }
}
